﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using LeMigue.Scrum.Iterface.Enum;

namespace LeMigue.Scrum.Iterface.Model
{
    /// <summary>
    /// Representação de um bug
    /// </summary>
    public class Bug : ScrumItem, IHasTask, IHasBacklog, IHasIteration
    {

        /// <summary>
        /// Armazena o Lazy List das tarefas
        /// </summary>
        internal Lazy<IList<Task>> _tasks;

        private BugState _state = BugState.New;

        public Iteration Iteration { get; set; }

        /// <summary>
        /// Contrutor para um novo Bug
        /// </summary>
        public Bug() : base() { }

        /// <summary>
        /// Contrutor de um Bug já cadastrado
        /// </summary>
        /// <param name="id">Id do bug</param>
        /// <param name="title">Titulo do bug</param>
        public Bug(int id, string title)
            : base(id, title)
        {
        }

        /// <summary>
        /// Lista das tarefas pertencetes ao Bug
        /// </summary>
        public IList<Task> Tasks
        {
            get { return new ReadOnlyCollection<Task>(_tasks.Value); }
        }

        /// <summary>
        /// Estado do bug
        /// </summary>
        public BugState State
        {
            get { return _state; }
            set { _state = value; }
        }

        /// <summary>
        /// Setar o Lazy para carregamento das tarefas
        /// </summary>
        /// <param name="tasks">Lazy das tarefas</param>
        public void SetTasks(Lazy<IList<Task>> tasks)
        {
            _tasks = tasks;
        }

        /// <summary>
        /// Retorna se tem ou não tarefas
        /// </summary>
        public bool HasTask
        {
            get { return Tasks.Count > 0; }
        }

        public IList<ItemBacklog> Backlogs
        {
            get { return new List<ItemBacklog>(); }
        }

        public void SetBacklogs(Lazy<IList<ItemBacklog>> backlogs)
        {
            throw new NotImplementedException();
        }

        public bool HasBacklog
        {
            get { return false; }
        }

        
    }
}
